package com.project.service;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.dao.impl.UserDaoImpl;
import com.project.server.Request;
import com.project.server.Response;
import com.project.server.Servlet;
import com.project.server.WebServlet;

import java.time.LocalDate;

/**
 * 添加业务组件
 */
@WebServlet("add")
public class AddService implements Servlet {
    private IUserDao userDao = new UserDaoImpl();

    public void service(Request request, Response response){
        //得到表单数据，封装成用户对象
        UserBean user = new UserBean();
        user.setName(request.getParameter("userName"));
        user.setPwd(request.getParameter("pwd"));
        user.setBirthday(LocalDate.parse(request.getParameter("birthday")));
        user.setMoney(Integer.parseInt(request.getParameter("money")));

        //调用持久方法，完成添加
        userDao.add(user);
        FindAllService findAllService = new FindAllService();
        findAllService.service(request,response);
    }
}
